/*
 *@本JS功能：学生统计详情
 *@本js作者：杨锡君
 *@编写时间：2018年2月27日
 */
$(function() {
	var loading1 = new Loading();
	loading1.init();
	var $tableBox = $(".tableBox");
	var th = "<tr>" +
		"<th class=\"col-lg-1\">序号</th>" +
		"<th class=\"col-lg-3\">章节</th>" +
		"<th class=\"col-lg-2\">成绩</th>" +
		"<th class=\"col-lg-2\">班级平均成绩</th>" +
		"<th class=\"col-lg-1\">实验时长</th>" +
		"<th class=\"col-lg-1\">班级平均时长</th>" +
		"</tr>";
	function tabelModel(opt,state) {
		return "<tr data-num=\"0\">" +
			"<td class=\"col-lg-1\">"+ state +"</td>" +
			"<td class=\"col-lg-3\" title='" + opt.chapterName + "'>" + opt.chapterName + "</td>" +
			"<td class=\"col-lg-2\">" + opt.taskSoruce + "分</td>" +
			"<td class=\"col-lg-2\" >" + opt.avgSource + "分</td>" +
			"<td class=\"col-lg-1\">" + Number((opt.usage_time/3600).toFixed(2)) + "h</td>" +
			"<td class=\"col-lg-1\">" +  Number((opt.avgLongTime/3600).toFixed(2)) + "h</td>" +
			"</tr>";
	}
	var classMana = {
		init: function() {
			this.bindEvent();
		},
		bindEvent: function() {
			var self = this;
			var json = {
				"pageNow": 1,
				"pageSize": 10,
				"classId":Number(result.paramData.classId),
				"courseId":Number(result.paramData.courseId),
				"stuorteaId":result.paramData.stuorteaId
			};
			self.tabelList(json);
			$(".looktg").off("click").click(function () {
                var json = JSON.stringify({
                    "pageName":"stuStatistics",
                    "paramData":{
                        "courseId":Number(result.paramData.courseId),
                        "classId":Number(result.paramData.classId)
                    }
                });
                window.location.href = "skipPage?jsonStr="+json;
            });
			$(".classInfo").html("<b>"+ result.paramData.className +" . </b>"+ result.paramData.courseName +" . "+ result.paramData.userName +"的信息详情");
		},
		tabelList: function(jsons) {
			var self = this;
			var json = JSON.stringify(jsons);
			loading1.show();
			$.ajax({
				type: "post",
				url: "getStuStatisticsDetailByStuId",
				data: {
					"jsonStr": json
				},
				async: true,
				success: function(msg) {
					loading1.hide();
					msg = JSON.parse(msg);
					$tableBox.empty();
					if(msg.result == "success"){
                        if( msg.stuStatisticsDetailMap.finalList != null) {
                            //列表
                            var tabel = "";
                            var state = 0;
                            $.map(msg.stuStatisticsDetailMap.finalList, function(opt) {
                                state++;
                                tabel += tabelModel(opt,state);
                            });
                            $tableBox.append(th + tabel);

                        } else {
                            var trImg = "<tr><td colspan='6'><img style='margin: 80px auto 20px;' src='pc/images/ico_noneData.png'><p style='font-size:26px;color:#8a8a8a;width:100%;text-align:center;'>暂无数据</p></td></tr>";
                            $tableBox.append(th + trImg)
                        }
                        var sumpage = msg.stuStatisticsDetailMap.totalPage;
                        if(sumpage != undefined){
                            if(sumpage == 0){
                                sumpage = 1;
                            }
                        }else{
                            sumpage = 1;
                        }

                        var nowpage = 1;
                        var pagenumber = 10;
                        $(".tcdPageCode").createPage({
                            pageCount: sumpage, //总页数
                            current: nowpage, //当前页数
                            pageNumber: pagenumber, //每页显示数量
                            backFn: function(p) {
                                nowpage = p;
                                if(nowpage >= sumpage) {
                                    nowpage = sumpage;
                                }
                                var jsonStr = jsons;
                                jsonStr.pageNow = nowpage;
                                loading1.show();
                                $.ajax({
                                    type: "post",
                                    url: "getStuStatisticsDetailByStuId",
                                    data: {
                                        "jsonStr":JSON.stringify(jsonStr)
                                    },
                                    async: true,
                                    success: function(msg) {
                                        loading1.hide();
                                        msg = JSON.parse(msg);
                                        //列表
                                        $tableBox.empty();
                                        var tabel = "";
                                        var state = (nowpage-1)*10;
                                        $.map(msg.stuStatisticsDetailMap.finalList, function(opt) {
                                            state++;
                                            tabel += tabelModel(opt,state);
                                        });
                                        $tableBox.append(th + tabel);
                                    }
                                });
                            }
                        });
					}else{
                        if(msg.failMsg != undefined){
                            if(msg.failMsg == "暂无权限"){
                                parent.location.reload(true);
                            }else{
                                Alert1.content = msg.failMsg;
                                Alert1.init();
                                Alert1.show();
                            }
                        }else{
                            if (msg.errorMsg != "" && msg.errorMsg != undefined) {
                                Alert1.content = msg.errorMsg;
                            } else {
                                Alert1.content = "获取失败";
                            }
                            Alert1.init();
                            Alert1.show();
                        }
					}


				}
			});

		}

	};
	classMana.init();
});